﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SO_DataFetcher.PubFunctions
{
    public class PubControls
    {
        public static RichTextBox LogRichTextBox;
        public static ToolStripStatusLabel LabelToolStatus;
        public static ToolStripProgressBar ProgressBarToolStrip;

        public static DataGridView DataGridViewActions;

        public static void InitialDataGridView(DataGridView dataGridView)
        {
            dataGridView.AllowUserToAddRows = false;
            dataGridView.AllowUserToDeleteRows = false;
            dataGridView.AllowUserToResizeRows = false;
            dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView.MultiSelect = false;
            dataGridView.RowHeadersVisible = true;
            dataGridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
            dataGridView.ReadOnly = true;
            dataGridView.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView_DataBindingComplete);
        }


        /// <summary>
        /// 设置DataGrid颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void dataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            try
            {
                DataGridView dataGridView = (DataGridView)sender;
                if (dataGridView.Rows.Count != 0)
                {
                    for (int i = 0; i < dataGridView.Rows.Count; i++)
                    {
                        if ((i % 2) == 1)
                        {
                            dataGridView.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
                        }
                        else
                        {
                            dataGridView.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

    }
}
